function isVisible (el: any) {
  const position = el.getBoundingClientRect()
  const windowHeight = document.documentElement.clientHeight
  // 顶部边缘可见
  const topVisible = position.top > 0 && position.top < windowHeight
  // 底部边缘可见
  const bottomVisible = position.bottom < windowHeight && position.bottom > 0
  return topVisible || bottomVisible
}

export function imageLazyLoad () {
  const images: any = document.querySelectorAll('img')
  for (const img of images) {
    const realSrc = img.dataset.src
    if (!realSrc) continue
    if (isVisible(img)) {
      img.src = realSrc
      img.dataset.src = ''
    }
  }
}
